import * as Resources from '../../services/Editor/resource';

export default {
    namespace: 'resources',
    state: {},
    reducers: {
        save(prevState, { payload: state }) {
            prevState[state.md5] = state.data;
            return { ...prevState };
        },
        saveResource(oldState, { payload: data }) {
            return { ...oldState,...data};
        },
    },
    effects: {
        *queryThreedState({ payload: md5 }, { put, call }) {
            const { data } = yield call(Resources.queryThreedState, md5);
            yield put({
                type: 'save',
                payload: {
                    md5,
                    data,
                },
            });
        },
        *requestResource({ payload: resourceId }, { put, call }) {
            const { data } = yield call(Resources.requestResource, resourceId);
            yield put({
                type: 'saveResource',
                payload: {
                    list:data
                }
            });
        },
        *importOtherResource({ payload: resourceId }, { put, call }) {
            yield call(Resources.importOtherResource, resourceId);
            //更新pages
            yield put({
                type: 'page/updatePage',
                payload: {}
            });
        },
    },
    subscriptions: {
    },
};
